<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
       报修工单-增加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div class="x-body">
    <div class="main_box">
        <div class="panel-heading">
            <h2>增加报修工单</h2>
        </div>
    </div>

    <form class="layui-form x-center" id="app">
        <h3 style="text-align: left;">电梯信息</h3>
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">

                <label class="layui-form-label">使用单位</label>
                <div class="layui-input-block">
                    <select id="companyId" name="companyId" lay-filter="brickType">
                        <option value="">请选择</option>

                    </select>
                </div>

            </div>
            <div class="layui-form-item">

                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-block">
                    <select name="projectId" id="projectId" lay-filter="getdianti">
                        <option value="">请选择</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">

                <label class="layui-form-label">电梯位置</label>
                <div class="layui-input-block">
                    <select name="elevatorId" id="elevatorId" lay-filter="getprogram">
                        <option value="">请选择</option>

                    </select>
                </div>

            </div>

            <h3 style="text-align: left;">故障信息</h3>
            <div class="layui-form-item">

                <label class="layui-form-label">选择故障</label>
                <div class="layui-input-inline">
                    <div id="demo1" class="xm-select-demo" ></div>
                </div>

            </div>

            <h3 style="text-align: left;">报修信息</h3>
            <div class="layui-form-item">
                <label class="layui-form-label">报修人员</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="repairperson" id="repairperson" placeholder="报修人员">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="tel" id="tel" placeholder="电话号码">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="remark" id="remark" placeholder="备注信息">
                </div>
            </div>

            <div style="text-align: center" class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                    保存
                </button>
            </div>
        </div>
    </form>



</div>
</body>

<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/myAjax.js"></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../js/xm-select.js" type="text/javascript" charset="utf-8"></script>



<script>


    const vm = new Vue({
        el: "#app",
        created() {

        },
        computed: {},
        methods: {

        },
        mounted(){
            //配置插件目录
            layui.config({
                base: '../../js/'
                , version: '1.0'
            });

            var demo1 = xmSelect.render({
                el: '#demo1',
                language: 'zn',
                filterable: true,
                toolbar: {
                    show: true,
                },
                autoRow: true,
                data: []
            });

            layui.use([ 'laydate', 'element', 'laypage', 'layer', 'form'],
                function () {
                    $ = layui.jquery;//jquery
                    laydate = layui.laydate;//日期插件
                    lement = layui.element;//面包导航
                    laypage = layui.laypage;//分页
                    layer = layui.layer;//弹出层
                    var form = layui.form;
                    okLoading.close($);


                    let request2 = {
                        url: 'maintenance/company/findAll',
                        method: "GET",
                        data:{userId: $userId}
                    };
                    sendRequest(request2, (res) => {
                        let x = res.data;
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                            $("#companyId").append(opt);
                        });
                        form.render('select');
                    });

                    let request3 = {
                        url: 'maintenance/project/findAll',
                        method: "GET",
                        data:{userId: $userId}
                    };
                    sendRequest(request3, (res) => {
                        let x = res.data;
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                            $("#projectId").append(opt);
                        });
                        form.render('select');
                    });

                    let request4 = {
                        url: 'maintenance/elevator/findAll',
                        method: "GET",
                        data:{userId: $userId}
                    };
                    sendRequest(request4, (res) => {
                        let x = res;
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.address + "</option>");
                            $("#elevatorId").append(opt);
                        });
                        form.render('select');
                    });

                    let request5 = {
                        url: 'user/getMaintenanceUser',
                        method: "GET",
                        data:{userId: $userId}
                    };
                    sendRequest(request5, (res) => {
                        let x = res;
                        $.each(x, function (index, item) {
                            let opt = $("<option value=" + item.id + ">" + item.nickname + "</option>");
                            $("#personId").append(opt);
                        });
                        form.render('select');
                    });

                    form.render('select');


                    form.on('select(brickType)', function(data){
                        let opthtml = $("<option value=''>请选择</option>");
                        $("#projectId").html(opthtml);
                        form.render('select');

                        var val=data.value;
                        if(val!=""){
                            let request = {
                                url: 'maintenance/project/findByCompanyId',
                                data: {
                                    companyId: val,
                                    userId: $userId
                                },
                                method: "POST",
                            };
                            sendRequest(request, (res) => {
                                let x = res.data;
                                $.each(x, function (index, item) {
                                    let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                                    $("#projectId").append(opt);
                                });
                                form.render('select');
                            });
                        }

                    });

                    form.on('select(getdianti)', function(data){

                        let opthtml = $("<option value=''>请选择</option>");
                        $("#elevatorId").html(opthtml);
                        form.render('select');
                        var val=data.value;
                        if(val!=""){
                            let request = {
                                url: 'maintenance/elevator/findByProjectId',
                                data: {
                                    projectId: val,
                                    userId: $userId
                                },
                                method: "POST",
                            };
                            sendRequest(request, (res) => {
                                let x = res;
                                $.each(x, function (index, item) {
                                    let opt = $("<option value=" + item.id + ">" + item.address + "</option>");
                                    $("#elevatorId").append(opt);
                                });
                                form.render('select');
                            });
                        }

                    });

                    form.on('select(getprogram)', function (data) {
                        var val=data.value;
                        if(val!=""){
                            let request = {
                                url: '/maintenance/maintainprogram/findByElevatorId',
                                method: 'POST',
                                data: {
                                    userId: $userId,
                                    elevatorId: data.value
                                }
                            }
                            sendRequest(request, res => {

                                var datas = [];

                                $.each(res.data, function (index, item) {
                                    datas.push({
                                        name: item.program,
                                        value: item.id,
                                        selected: false
                                    })
                                });
                                demo1.update({
                                    data: datas
                                });

                            })

                        }



                    });

                    //监听审批提交
                    form.on('submit(sub)',
                        function (data) {
                            var elevatorId = $("#elevatorId").val();
                            var selectArr = demo1.getValue();


                            if(elevatorId == ""){
                                layer.msg("请选择电梯！", {
                                    icon: 5
                                });
                                return false;
                            }else if(selectArr.length==0){
                                layer.msg("请选择故障信息！", {
                                    icon: 5
                                });
                                return false;
                            }else{

                                var ids = '';
                                $.each(selectArr, function (index, item) {
                                    ids += item.value + ','
                                });

                                let form = data.field;
                                form.userId = $userId;
                                form.idString = ids;

                                let request = {
                                    url: 'maintenance/reportRepair/savehou',
                                    data: form,
                                    method: "post",
                                };
                                sendRequest(request, (data) => {
                                    if (data.code === 0) {
                                        layer.alert("操作成功", {
                                                icon: 6
                                            },
                                            function () {
                                                var index = parent.layer.getFrameIndex(window.name);
                                                parent.layer.close(index);
                                                parent.reload();
                                            });
                                    } else {
                                        layer.alert(data.msg, {
                                            icon: 5
                                        })
                                    }
                                });
                                return false;
                            }


                        });
                });



        }


    });

</script>




</html>
